package com.cyw.common.utils;

import java.util.*;

/**
 * @Author: Chenyw
 * @Date: 2022/11/10/14:36
 */
public class SetUtils {

    public static Set<Long> getContainSet(Set<Long> set1, Set<Long> set2) {
        Map<Long, Integer> map = new HashMap<Long, Integer>(set1.size() + set2.size());
        Set<Long> contain = new HashSet<>();
        Set<Long> maxSet = set1;
        Set<Long> minSet = set2;
        if (set2.size() > set1.size()) {
            maxSet = set2;
            minSet = set1;
        }

        for (Long in : maxSet) {
            map.put(in, 1);
        }

        for (Long in : minSet) {
            Integer cc = map.get(in);
            if (cc != null) {
                map.put(in, ++cc);
                continue;
            }
            map.put(in, 1);
        }

        for (Map.Entry<Long, Integer> entry : map.entrySet()) {
            if (entry.getValue() != 1) {
                contain.add(entry.getKey());
            }
        }
        return contain;
    }
}
